package ldh.im.fxbase.richtext;

import org.fxmisc.richtext.model.Codec;
import org.fxmisc.richtext.model.NodeSegmentOpsBase;

public enum TextItemType {
    emoji(new EmojiTextItemOps(), EmojiTextItem.createCodec()),
    image(new ImageTextItemOps(), ImageTextItem.createCodec()),
    audio(null, null),
    vedio(null, null),
    pdf(null, null),
    word(null, null),
    File(null, null),
    ;

    private NodeSegmentOpsBase textItemOps;
    private Codec<? extends TextItem> codec;

    private TextItemType(NodeSegmentOpsBase textItemOps, Codec<? extends TextItem> codec) {
        this.textItemOps = textItemOps;
        this.codec = codec;
    }

    public NodeSegmentOpsBase getTextItemOps() {
        return textItemOps;
    }

    public <O extends TextItem> O newTextItem(String data) {
        if (this == emoji) {
            return (O) new EmojiTextItem(data);
        } else if (this == image) {
            return (O) new ImageTextItem(data);
        }
        throw new RuntimeException("type: " + this.name() + "不支持");
    }

}
